<template>
  <div class="section-box">
    <FrameLayout>
      <template v-slot:left>
        <Frame title="防御预案" style="height: 100%">
          <template v-slot:body>
            <div class="yaTop">
              <div class="RightCardTitle">
                预案管理
              </div>
              <div class="form_span">
                <p><span>流域名称</span> {{ wswscdName }}</p>
                <p><span>行政区划</span><el-input v-model="formRule.adnm" placeholder="请输入内容"
                    @change="AddvnmFallBlur($event)" /></p>
                <p><span>预案级别</span>
                  <el-radio-group v-model="formRule.lvl">
                    <el-radio label="3" @click.native.prevent="LvlTypechange('3')">县级</el-radio>
                    <el-radio label="4" @click.native.prevent="LvlTypechange('4')">乡级</el-radio>
                    <el-radio label="5" @click.native.prevent="LvlTypechange('5')">村级</el-radio>
                  </el-radio-group>
                </p>
              </div>
              <div class="RightCardTitle">
                详情
              </div>
              <div class="listYa">
                <div class="titleList">
                  <span>序号</span>
                  <span>政区</span>
                  <span>上级</span>
                  <span>上报时间</span>
                  <span>操作</span>
                </div>
                <div>
                  <ul>
                    <li v-for="(item, index) in list" :key="index" :class="{ tableBgList: selectNum == index }"
                      @click.stop="listChange(item, index)">
                      <span>{{ index + 1 }}</span>
                      <span>{{ item.addvnm }}</span>
                      <span>{{ item.parentNm }}</span>
                      <span>{{ item.createTime ? $moment(item.createTime).format("YYYY/MM/DD") : '' }}</span>
                      <span style=" letter-spacing: -1px;">
                        <i @click.stop="UploadGet(item)">{{ item.id ? '更新' : '上传' }}</i>
                        <i v-if="item.id" @click.stop="getDeletePlan(item.id)">删除</i>
                      </span>
                    </li>
                    <infinite-loading ref="infiniteLoading" @infinite="infiniteHandler">
                      <span slot="no-more"> &nbsp; &nbsp; </span>
                      <template v-if="list.length <= 0">
                        <div slot="no-results" class="noData">当前无预案</div>
                      </template>
                      <div v-else slot="no-results"> &nbsp; &nbsp;</div>
                    </infinite-loading>
                  </ul>
                </div>
              </div>
            </div>
            <div>
              <div class="RightCardTitle">
                预案情况统计
              </div>
              <div v-loading="loading" element-loading-background="rgba(0, 0, 0, 0.4)" class="yaqktj_box">
                <div class="left_yaqktj">
                  <div>
                    <img src="~@/assets/newimg/StatisticsBg.png">
                    <span>{{ statist.Total }}</span>
                  </div>
                  <span>预案总数</span>
                </div>
                <div v-if="statist.Detail" class="rights_yaqktj">
                  <div>
                    <img src="~@/assets/newimg/yaXian.png">
                    <div>
                      <p>县级预案数：{{ statist.Detail[0].Total }}</p>
                      <p>待更新数：{{ statist.Detail[0].UnUpdate }}</p>
                    </div>
                  </div>
                  <div>
                    <img src="~@/assets/newimg/yaXiang.png">
                    <div>
                      <p>乡级预案数：{{ statist.Detail[1].Total }}</p>
                      <p>待更新数：{{ statist.Detail[1].UnUpdate }}</p>
                    </div>
                  </div>
                  <div>
                    <img src="~@/assets/newimg/yaCun.png">
                    <div>
                      <p>村级预案数：{{ statist.Detail[2].Total }}</p>
                      <p>待更新数：{{ statist.Detail[2].UnUpdate }}</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </template>
        </Frame>
      </template>
    </FrameLayout>
    <Dlgdiv v-if="this.$store.getters.dlgParams.name === 'reserveUpload'" mask class="uploadDlog">
      <template v-slot:body>
        <el-upload v-loading="loadingUpload" class="upload-demo" drag action="111" :accept="acceptFile('filepdf')"
          :before-upload="beforeUpload" element-loading-text="上传中" element-loading-background="rgba(0, 0, 0, 0.4)">
          <i class="el-icon-upload" />
          <div class="el-upload__text"><em>点击上传</em></div>
          <div slot="tip" class="el-upload__tip">只能上传pdf文件</div>
        </el-upload>
      </template>

    </Dlgdiv>
    <Dlgdiv v-if="this.$store.getters.dlgParams.name === 'reserveSee'" class="reserveSee" mask>
      <template v-slot:body>
        <ReserveplanDlg />
      </template>
    </Dlgdiv>
  </div>
</template>
<script>
import { GetPlanList, PlanStatistics, DeletePlan, UploadFloodPlan, InsertFloodPlan } from '../../../api/xuna.js'
import {
  mapGetters
} from 'vuex'
import Dlgdiv from '../../components/Dlgdiv.vue'
import ReserveplanDlg from '../../components/reserveplanDlg.vue'
// 村庄预案模块
import CZYA from '@/map/cesium/mixins/CZYA'

export default {
  name: 'Risk',
  components: {
    Dlgdiv,
    ReserveplanDlg
  },
  mixins: [CZYA],
  data() {
    return {
      formRule: {
        wswscd: '',
        lvl: '-1',
        adnm: '',
        page: 1,
        limt: 10
      },
      wswscdName: '',
      list: [],
      selectNum: -1,
      statist: {},
      loading: false,
      uploadForm: {
        Addvcd: '',
        WordPath: ''
      },
      loadingUpload: false
    }
  },
  computed: {
    ...mapGetters({
      basin: 'basin',
      basinName: 'basinName'
    })
  },
  watch: {
    'basin': {
      immediate: true,
      deep: true,
      handler(val) {
        this.formRule.wswscd = val
        this.formRule.page = 1
        this.getGetPlanList()
        this.getPlanStatistics()
      }
    },
    'basinName': {
      immediate: true,
      deep: true,
      handler(val) {
        this.wswscdName = val
      }
    },
    addvcdurl(val, newval) {
      console.log(val, newval)
    }

  },
  created() {
    
    this.$store.dispatch('rightFold', true)
  },
  methods: {
    acceptFile(e) {
      const allowHook = {
        video: '.mp4, .ogv, .ogg, .webm',
        audio: '.wav, .mp3, .ogg, .acc, .webm, .amr',
        file: 'doc,.docx,.xlsx,.xls,.pdf',
        filepdf: '.pdf',
        img: '.jpg, .jpeg, .png, .gif'
      }
      if (e) {
        return allowHook[e]
      }
      let srt = null
      for (const k in allowHook) {
        srt += allowHook[k]
      }
      return srt
    },
    AddvnmFallBlur(e) {
      this.formRule.adnm = e
      this.resetList()
    },
    // 加载更多
    infiniteHandler($state) {
      this.getGetPlanList($state)
    },
    // 重置
    resetList() {
      this.formRule.page = 1
      this.list = []
      this.$nextTick(() => {
        //  console.log(this.$refs.infiniteLoading)
        this.$refs.infiniteLoading.$emit('$InfiniteLoading:reset')
      })
      // 如果需要在查询条件变化时刷新地图，放开下一行代码
      // this.creatCZYA(this.formRule)
    },
    getGetPlanList($state) {
      GetPlanList(this.formRule).then((res) => {
        if ($state) {
          if (!res.data || res.data.length < this.formRule.limt) {
            if (res.data.length !== 0) {
              const arr = res.data
              this.list = [...this.list, ...arr]
            }
            $state.complete() // 加载完成的状态
          } else {
            const arr = res.data
            this.list = [...this.list, ...arr]
            if (res.data.length < this.formRule.limt) {
              $state.complete() // 加载完成的状态
            } else {
              $state.loaded() // 加载中的状态
            }
          }
          this.selectNum = -1
        } else {
          this.list = res.data
        }
        this.formRule.page++
      })
      if (!$state) {
        // 非加载更多时 的 调用
        this.creatCZYA(this.formRule)
      }
    },
    // 统计
    getPlanStatistics() {
      this.loading = true
      PlanStatistics({ wswscd: this.formRule.wswscd }).then((res) => {
        this.loading = false
        this.statist = res.data
      })
    },
    // 删除
    getDeletePlan(id) {
      this.$confirm('确定删除吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        DeletePlan({ id: id }).then((res) => {
          this.loading = false
          if (res.isSuccess) {
            this.$message({
              type: 'success',
              message: res.message
            })
          } else {
            this.$message({
              type: 'info',
              message: res.message
            })
          }
          this.resetList()
          this.getPlanStatistics()
        })
      })
    },
    LvlTypechange(e) {
      e === this.formRule.lvl ? (this.formRule.lvl = '-1') : (this.formRule.lvl = e)
      this.resetList()
    },
    listChange(item, index) {
      this.selectNum = index
      this.flyToVillShowPopCZYA(item.addvcd)
    },
    // 上传
    UploadGet(item) {
      // console.log(item)
      const dlgParams = this.$store.getters.dlgParams
      dlgParams.name = 'reserveUpload'
      this.$store.dispatch('dlgParams', dlgParams)
      this.uploadForm.Addvcd = item.addvcd
    },
    beforeUpload(file) {
      const fd = new FormData()
      this.files = file
      fd.append('file', file)
      this.loadingUpload = true
      UploadFloodPlan(fd).then((res) => {
        this.loadingUpload = false

        this.uploadForm.WordPath = res.data.Url
        this.getInsertFloodPlan()
      })
    },
    getInsertFloodPlan() {
      this.loadingUpload = true
      InsertFloodPlan(this.uploadForm).then((res) => {
        this.loadingUpload = false
        if (res.isSuccess) {
          this.$message({
            type: 'success',
            message: res.message
          })
        } else {
          this.$message({
            type: 'info',
            message: res.message
          })
        }
        const dlgParams = this.$store.getters.dlgParams
        dlgParams.name = ''
        dlgParams.params = null
        this.$store.dispatch('dlgParams', dlgParams)
        this.resetList()
        this.getPlanStatistics()
      })
    }

  }
}
</script>

<style lang="scss" scoped>
.reserveSee {
  width: 80% !important;
  ;
  height: 80% !important;
  top: calc(50% - 40%) !important;
  left: calc(50% - 40%) !important;
}

.uploadDlog::v-deep {
  // width: 450px !important;height:270px!important;top:30%!important;left:50%!important; margin-left:-220px;
  width: 450px;
  height: 270px;
  top: 30%;
  left: 50%;
  margin-left: -220px;

  .close {
    top: -10px;
    right: -25px;
  }

  // .mask{
  //  background-color:transparent;
  // }
}

.el-upload-dragger,
.el-upload {
  width: 100%;
  height: 160px;
}

.el-upload__tip {
  color: #fff;
  text-align: center;
}

.upload-demo {
  padding-top: 10px;
}

.section-box {
  height: 100%;
}

.form_span {
  p {
    margin-bottom: 5px;

    >span {
      color: #8FC0FC;
      width: 20%;
      font-size: 12px;
      display: inline-block;
      text-align: center;
    }

    .el-input,
    .el-radio-group {
      width: 79%;
      display: inline-block;
    }

    .el-radio-group {
      display: inline-flex;
      justify-content: space-between;

      label {
        margin: 0;
        width: 28%;
        text-align: center;
      }
    }
  }

}

.listYa {
  background: rgba(3, 34, 55, 0.39);
  padding: 0 5px 10px;
  height: 70%;
  overflow: hidden;

  >div {
    padding: 0;

    &:nth-child(2) {
      height: 95%;
      overflow: auto;
    }

    li {
      background: rgba(0, 43, 77, 0.78);
      display: flex;
      align-items: center;
      cursor: pointer;
      padding: 10px 0;
    }
  }

  .titleList {
    background-color: rgba(14, 81, 133, 0.65);
    padding: 5px 0;
  }

  span {
    display: inline-block;
    width: 22.4%;
    text-align: center;
    font-size: 12px;

    &:nth-child(1) {
      width: 10%;
    }
  }

  .infinite-status-prompt {
    span {
      width: 100%;
    }
  }

  i {
    font-style: normal;
    color: #fff;
    font-weight: 700;
    margin: 0 2px;
  }
}

.yaTop {
  //height: 65%;
  height: calc(100% - 255px);
}

.yaqktj_box {
  height: 35%;
  background: rgba(3, 34, 55, 0.39);
  overflow: hidden;
  padding: 20px 40px;

  .left_yaqktj {
    width: 74px;
    height: 100%;
    float: left;
    text-align: center;
    padding-top: 10%;

    >div {
      overflow: hidden;
      position: relative;

      img {
        width: 100%;
      }

      span {
        position: absolute;
        top: 25%;
        left: 0;
        font-size: 16px;
        z-index: 2;
        font-weight: 700;
        text-align: center;
        width: 100%;
      }
    }
  }

  .rights_yaqktj {
    float: right;
    font-size: 12px;
    text-align: right;

    >div {
      img {
        width: 30px;
        height: 30px;
        float: left;
      }

      margin-bottom: 20px;
      overflow: hidden;

      >div {
        float: left;
        margin-left: 10px;

        p:nth-child(2) {
          color: #75B0FC;
          margin-top: 5px;
          text-indent: 15px;
        }
      }
    }
  }
}
</style>
<style lang="scss">
// .uploadDlog{
//        .diadiv-inner{
//         .close{
//           top: -10px;
//           right: -25px;
//         }
//        }
//       }
</style>
